﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Se.Framework.Common.Security;

namespace Trust.Casas.Web.Security
{
    public class UsersInitializer
    {
        private const string SuperAdminRoleName = "SuperAdmin";

        private const string SebasUserName = "Sebas";

        private const string LeoUserName = "Leo";

        public static void CreateDefaultUsers()
        {
            var userManager = Se.Framework.Common.ObjectRegistry.Current.Resolve<IUserManager>();

            if (!userManager.Exists(SebasUserName))
                userManager.Create(SebasUserName, "123qweasd");
            if (!userManager.Exists(LeoUserName))
                userManager.Create(LeoUserName, "123qweasd");

            var roleManager = Se.Framework.Common.ObjectRegistry.Current.Resolve<IRoleManager>();

            if (!roleManager.Exists(SuperAdminRoleName))
            {
                roleManager.Create(SuperAdminRoleName);
                roleManager.AddUserToRole(SebasUserName, SuperAdminRoleName);
                roleManager.AddUserToRole(LeoUserName, SuperAdminRoleName);
            }
        }
    }
}